package com.nd.android.musicboxlibrary.ui.vip;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.common.utils.StarAppUtils;
import com.nd.android.musicboxlibrary.R;
import com.nd.android.musicboxlibrary.util.TypefaceUtil;

public class RenewVipConfirmDialog extends Dialog
        implements View.OnClickListener {

    public interface OnUserSelectListener {
        public void onConfirm();
        public void onCancel();
    }

    private OnUserSelectListener mUserSelectListener;

    private ViewGroup mLayoutRoot;

    private TextView mTextName;
    private TextView mTextPrice;
    private Button mBtnCancel;
    private Button mBtnOk;

    private String mStrName = "";
    private String mStrPrice = "";

    public RenewVipConfirmDialog(Context context, int theme) {
        super(context, theme);
    }

    public RenewVipConfirmDialog(Context context) {
        super( context, R.style.TransparencyDialog );
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView( R.layout.mbx_renew_vip_confirm_dialog );
        setupViews();
    }

    private void setupViews() {
        mLayoutRoot = (ViewGroup) findViewById( R.id.layout_root );

        mTextName = (TextView) findViewById( R.id.text_desc_name );
        mTextPrice = (TextView) findViewById( R.id.text_desc_price );

        mBtnCancel = (Button) findViewById( R.id.btn_cancel );
        mBtnOk = (Button) findViewById( R.id.btn_ok );

        mBtnCancel.setOnClickListener( this );
        mBtnOk.setOnClickListener( this );

        TypefaceUtil.setFontRecursion( mLayoutRoot );
        //字体
        StarAppUtils.setViewTypeFace(mTextName, false);
        StarAppUtils.setViewTypeFace(mTextPrice, false);
    }

    public void setupInfos(String name, String price) {
        mStrName = name;
        mStrPrice = price;
    }

    @Override
    public void show() {
        super.show();

        if ( mTextName != null ) {
            mTextName.setText( mStrName );
        }

        if ( mTextPrice != null ) {
            mTextPrice.setText( mStrPrice );
        }
    }

    @Override
    public void onClick(View v) {
        if ( v == mBtnCancel ) {
            if ( mUserSelectListener != null ) {
                mUserSelectListener.onCancel();
            }
            dismiss();
        } else if ( v == mBtnOk ) {
            if ( mUserSelectListener != null ) {
                mUserSelectListener.onConfirm();
            }
            dismiss();
        }
    }

    public void setUserSelectListener(OnUserSelectListener listener) {
        this.mUserSelectListener = listener;
    }

}
